package com.yanqu.road.server.manger.config.grandchild.skill.enums;

import com.yanqu.road.entity.grandchild.GrandChildData;
import com.yanqu.road.server.manger.config.grandchild.skill.condition.SkillConditionTAA;
import com.yanqu.road.server.manger.config.grandchild.skill.condition.SkillConditionTOM;
import com.yanqu.road.server.manger.config.grandchild.skill.param.GrandChildSkillConditionParam;
import com.yanqu.road.server.manger.config.grandchild.skill.condition.SkillConditionNOCOND;
import com.yanqu.road.server.manger.config.grandchild.skill.condition.SkillConditionQUA;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;

/**
 * 前提随机条件
 */
public enum eGrandChildSkillCondition {

    NOCOND("NOCOND", SkillConditionNOCOND::canRandom), // 【无条件】

    QUA("QUA", SkillConditionQUA::canRandom), // 资质

    TAA("TAA", SkillConditionTAA::canRandom), // 孙子总天资

    TOM("TOM", SkillConditionTOM::canRandom), // 最高天资为xx职业
    ;

    private static Map<String, eGrandChildSkillCondition> cacheMap = new ConcurrentHashMap<>();

    static {
        for (eGrandChildSkillCondition value : values()) {
            cacheMap.put(value.name, value);
        }
    }

    private String name;
    private BiFunction<GrandChildData, GrandChildSkillConditionParam, Boolean> function;

    eGrandChildSkillCondition(String name, BiFunction<GrandChildData, GrandChildSkillConditionParam, Boolean> function) {
        this.name = name;
        this.function = function;
    }

    public static boolean canRandom(GrandChildData data, GrandChildSkillConditionParam param) {
        eGrandChildSkillCondition skillCondition = cacheMap.get(param.getName());
        return skillCondition.function.apply(data, param);
    }

}
